using System;

namespace SharpMud.Scripting.Metadata
{
	/// <summary>
	/// Defines an abstract implementation fo IScriptLanguageDefinition
	/// </summary>
	public abstract class ScriptLanguageDefinition : IScriptLanguageDefinition
	{
		#region Private Variables
		private System.Collections.Specialized.StringCollection _LanguageNames;
		private System.Guid										_LanguageGuid;
		#endregion

		#region Constructors
		/// <summary>
		/// The default constructor for ScriptLanguageDefinition
		/// </summary>
		protected ScriptLanguageDefinition()
		{
			_LanguageGuid = System.Guid.Empty;
			_LanguageNames = new System.Collections.Specialized.StringCollection();
		}
		/// <summary>
		/// Instanciates an instance of ScriptLanguageDefinition, with the specification of
		/// what the language guid is
		/// </summary>
		/// <param name="languageGuid">The guid of the script language</param>
		protected ScriptLanguageDefinition(System.Guid languageGuid)
		{
			_LanguageGuid = languageGuid;
		}

		/// <summary>
		/// Instanciates an instance of ScriptLanguageDefinition, with the specification of
		/// what the language guid is, and what language aliases it associates with
		/// </summary>
		/// <param name="languageGuid">The guid of the script language</param>
		/// <param name="languageNames">The aliases of the script language</param>
		protected ScriptLanguageDefinition(System.Guid languageGuid, params string[] languageNames)
		{
			_LanguageGuid = languageGuid;
			_LanguageNames = new System.Collections.Specialized.StringCollection();
			_LanguageNames.AddRange(languageNames);
		}

		/// <summary>
		/// Instanciates an instance of ScriptLanguageDefinition, with the specification of
		/// what the language aliases are
		/// </summary>
		/// <param name="languageNames">The aliases of the script language</param>
		protected ScriptLanguageDefinition(params string[] languageNames)
		{
			_LanguageGuid = System.Guid.Empty;
			_LanguageNames = new System.Collections.Specialized.StringCollection();
			_LanguageNames.AddRange(languageNames);
		}
		#endregion

		#region Public Properties
		/// <summary>
		/// The list of names that the script language identifies with
		/// </summary>
		public System.Collections.Specialized.StringCollection LanguageNames
		{
			get
			{
				return _LanguageNames;
			}
		}
		/// <summary>
		/// The unique identifier for the script language
		/// </summary>
		public System.Guid LanguageGuid
		{
			get
			{
				return _LanguageGuid;
			}
		}
		#endregion

		#region Public Methods
		/// <summary>
		/// Determines if the script language identfies with the given alias
		/// </summary>
		public bool HasAlias(string languageAlias)
		{
			if(LanguageNames.Contains(languageAlias))
				return true;

			System.Guid g;
			try
			{
				g = new System.Guid(languageAlias);
			}
			catch
			{
				return false;
			}
			
			if(g!=System.Guid.Empty && g==_LanguageGuid)
			{
				return true;
			}

			return false;
		}
		/// <summary>
		/// Determines if the given guid is that of the script language
		/// </summary>
		public bool HasAlias(Guid languageGuid)
		{
			if(languageGuid!=System.Guid.Empty && languageGuid==_LanguageGuid)
			{
				return true;
			}
			return false;
		}
		#endregion
	}
}
